]> git.r.bdr.sh - rbdr/super-polarity/blobdiff - Super Polarity/Actors/MainShip.cs
I have the worst commits ever.
[rbdr/super-polarity] / Super Polarity / Actors / MainShip.cs
index 1f4f22ac2128d0e194ef025f370bb90b01588ca7..616f16e507779277b65fe0a0114a03b98e731368 100644 (file)
@@ -20,7 +20,11 @@ namespace SuperPolarity
         protected bool Shooting;
         protected int ShotCooldown;
 
-        public MainShip(Game newGame) : base(newGame) {}
+        protected float CurrentImmortalTime;
+        protected float MaxImmortalTime;
+        protected bool Flashing;
+
+        public MainShip(SuperPolarity newGame) : base(newGame) {}
 
         ~MainShip()
         {
@@ -38,6 +42,13 @@ namespace SuperPolarity
             SetPolarity(Polarity.Positive);
 
             ShotCooldown = 50;
+            MaxImmortalTime = 1500;
+
+            BoxDimensions.X = 2;
+            BoxDimensions.Y = 2;
+            BoxDimensions.W = 2;
+            BoxDimensions.Z = 2;
+            InitBox();
 
             BindInput();
         }
@@ -57,7 +68,11 @@ namespace SuperPolarity
 
         protected void HandleShot(float value)
         {
-            Children.Add(ActorFactory.CreateBullet(Position, Angle));
+            var bullet = ActorFactory.CreateBullet(Position, Angle);
+
+            Children.Add(bullet);
+            bullet.Parent = this;
+
             Shooting = true;
             Timer t = new Timer(new TimerCallback(UnlockShot));
             t.Change(ShotCooldown, Timeout.Infinite);
@@ -97,6 +112,7 @@ namespace SuperPolarity
         {
             base.SwitchPolarity();
             SwitchParticleEngine(CurrentPolarity);
+            game.Player.ResetMultiplier();
         }
 
         public override void SetPolarity(Polarity newPolarity)
@@ -127,9 +143,35 @@ namespace SuperPolarity
             particleEngine.EmitterLocation = Position;
             particleEngine.Update();
             ConstrainToEdges();
+            UpdateImmortality(gameTime);
             Shooting = false;
         }
 
+        public void UpdateImmortality(GameTime gameTime)
+        {
+            if (Immortal)
+            {
+                CurrentImmortalTime += gameTime.ElapsedGameTime.Milliseconds;
+
+                if (Flashing)
+                {
+                    Color = new Color(255, 255, 255, 128);
+                }
+                else
+                {
+                    Color = Color.White;
+                }
+
+                Flashing = !Flashing;
+
+                if (CurrentImmortalTime > MaxImmortalTime)
+                {
+                    Immortal = false;
+                    Color = Color.White;
+                }
+            }
+        }
+
         public override void Move(GameTime gameTime)
         {
             base.Move(gameTime);
@@ -207,5 +249,28 @@ namespace SuperPolarity
             particleEngine.Draw(spriteBatch);
             base.Draw(spriteBatch);
         }
+
+        public override void Collide(Actor other, Rectangle collision)
+        {
+            if (other.GetType().IsAssignableFrom(typeof(StandardShip)) &&
+                            !Immortal)
+            {
+                Die();
+            }
+        }
+
+        protected override void Die()
+        {
+            game.Player.Lives = game.Player.Lives - 1;
+            game.Player.ResetMultiplier();
+            if (game.Player.Lives < 0)
+            {
+                Dying = true;
+            }
+            else {
+                Immortal = true;
+                CurrentImmortalTime = 0;
+            }
+        }
     }
 }